//lwnotice("output: %s", str);
}
+
+char getMachineEndian()
+{
+ static int endian_check_int = 1; // dont modify this!!!
+
+ return *((char *) &endian_check_int); // 0 = big endian | xdr,
+ // 1 = little endian | ndr
+}
+
+
#define WKBZOFFSET 0x80000000
#define WKBMOFFSET 0x40000000
+#define WKBSRIDFLAG 0x20000000
+#define WKBBBOXFLAG 0x10000000
#define TYPE_SETTYPE(c,t) ((c)=(((c)&0xF0)|(t)))
#define TYPE_SETZM(t,z,m) ((t)=(((t)&0xCF)|((z)<<5)|((m)<<4)))
/* Utilities */
extern void trim_trailing_zeros(char *num);
+/* Machine endianness */
+#define XDR 0
+#define NDR 1
+extern char getMachineEndian(void);
+
#endif // !defined _LIBLWGEOM_H
#include "stringBuffer.h"
-#define DEBUG 1
+//#define DEBUG 1
#include "lwgeom_pg.h"
#include "wktparse.h"
size_header = sprintf(sridText,"SRID=%i;",SRID);
//SRID text size + wkb size (+1 = NULL term)
- size_result = size_header + 2*(wkb_input->size -4) + 1;
+ size_result = size_header + 2*(wkb_input->size-4) + 1;
wkb_srid_hexized = palloc(size_result);
wkb_srid_hexized[0] = 0; // empty
if ( ! strncmp(VARDATA(type), "xdr", 3) ||
! strncmp(VARDATA(type), "XDR", 3) )
{
- byteorder = BIG_ENDIAN;
+ byteorder = XDR;
}
else
{
- byteorder = LITTLE_ENDIAN;
+ byteorder = NDR;
}
}
#endif
#ifdef DEBUG
- elog(NOTICE, "LWGEOMFromWKB returned %s", unparse_WKB(SERIALIZED_FORM(result),pg_alloc,pg_free,-1));
+ elog(NOTICE, "LWGEOM_from_bytea returned %s", unparse_WKB(SERIALIZED_FORM(result),pg_alloc,pg_free,-1));
#endif
void set_zm(char z, char m);
void close_parser(void);
-#undef LITTLE_ENDIAN
-#define LITTLE_ENDIAN 1
-char getMachineEndian()
-{
- static int endian_check_int = 1; // dont modify this!!!
-
- return *((char *) &endian_check_int); // 0 = big endian, 1 = little endian
-}
-
-
typedef unsigned long int4;
typedef struct tag_tuple tuple;
WRITE_INT4(output_state * out,int4 val)
{
if ( val <= 0x7f ){
- if ( getMachineEndian() == LITTLE_ENDIAN ){
+ if ( getMachineEndian() == NDR ){
val = (val<<1) | 1;
}
else{
the_geom.alloc_size-=3;
}
else{
- if ( getMachineEndian() == LITTLE_ENDIAN ){
+ if ( getMachineEndian() == NDR ){
val <<=1;
}
WRITE_INT4_REAL(out,val);
byte xdr = read_wkb_byte(b);
swap_order=0;
- if ( xdr == 0x01 ){ // wkb is in little endian
- if ( getMachineEndian() != LITTLE_ENDIAN )
- swap_order=1;
- }
- else if ( xdr == 0x00 ){ // wkb is in big endian
- if ( getMachineEndian() == LITTLE_ENDIAN )
- swap_order=1;
+ if ( xdr != getMachineEndian() )
+ {
+ swap_order=1;
}
type = read_wkb_int(b);
}
else the_geom.hasM = 0;
+ if (type & WKBSRIDFLAG )
+ {
+ the_geom.hasZ = 1;
+ the_geom.ndims++;
+ }
+
type &=0x0f;
if ( the_geom.lwgi ){
byte* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
byte* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
char* unparse_WKT(byte* serialized, allocator alloc,freeor free);
-char* unparse_WKB(byte* serialized, allocator alloc,freeor free, unsigned int endian);
+char* unparse_WKB(byte* serialized, allocator alloc,freeor free, char endian);
-char getMachineEndian();
#include "liblwgeom.h"
-static int endian_check_int = 1; // dont modify this!!!
-
-#define LITTLE_ENDIAN_CHECK 1
-static unsigned int getMachineEndian()
-{
- // 0 = big endian, 1 = little endian
- if ( *((char *) &endian_check_int) )
- {
- return LITTLE_ENDIAN;
- }
- else
- {
- return BIG_ENDIAN;
- }
-}
-
//-- Typedefs ----------------------------------------------
typedef unsigned long int4;
{
int4 ret;
#ifdef SHRINK_INTS
- if ( getMachineEndian() == LITTLE_ENDIAN_CHECK ){
+ if ( getMachineEndian() == NDR ){
if( (**geom)& 0x01){
ret = **geom >>1;
(*geom)++;
memcpy(&ret,*geom,4);
#ifdef SHRINK_INTS
- if ( getMachineEndian() == LITTLE_ENDIAN_CHECK ){
+ if ( getMachineEndian() == NDR ){
ret >>= 1;
}
#endif
}
char *
-unparse_WKB(byte* serialized, allocator alloc, freeor free, unsigned int endian)
+unparse_WKB(byte* serialized, allocator alloc, freeor free, char endian)
{
#ifdef DEBUG
out_start = out_pos = alloc(len);
lwgi=0;
- if ( endian == -1 ) endian = getMachineEndian();
-
- if ( endian == LITTLE_ENDIAN) endianbyte=1;
- else endianbyte=0;
-
- if ( endian != getMachineEndian() ) flipbytes = 1;
- else flipbytes = 0;
+ if ( endian == -1 ) {
+ endianbyte = getMachineEndian();
+ flipbytes = 0;
+ } else {
+ endianbyte = endian;
+ if ( endianbyte != getMachineEndian() ) flipbytes = 1;
+ else flipbytes = 0;
+ }
output_wkb(serialized);
ensure(1);
/******************************************************************
* $Log$
+ * Revision 1.14 2004/12/17 11:08:53 strk
+ * Moved getMachineEndian from parser to liblwgeom.{h,c}.
+ * Added XDR and NDR defines.
+ * Fixed all usage of them.
+ *
* Revision 1.13 2004/10/25 12:27:33 strk
* Removed useless network type includes,
* Added param.h include for BYTE_ORDER defines under win32.