283b622013-03-26Martin Nilsson #pike __REAL_VERSION__
71e1342013-02-17Bill Welliver  constant BSONBinary = 1; static string data; static int subtype = 0x00; //! static void create(string _data, int|void _subtype) { subtype = _subtype; if(subtype == .BINARY_OLD) {
dd08cc2013-05-19Martin Nilsson  if( !sscanf(data, "%-4H", data) ) throw(Error.Generic("old binary data length does not match actual data length.\n"));
71e1342013-02-17Bill Welliver  } else data = _data; } int get_subtype() { return subtype; } void set_subtype(int _subtype) { subtype = _subtype; }
dd08cc2013-05-19Martin Nilsson 
71e1342013-02-17Bill Welliver  static int _sizeof() { if(subtype == .BINARY_OLD) return sizeof(data) + 4; else return sizeof(data); } static mixed cast(string type) { if(type == "string") {
dd08cc2013-05-19Martin Nilsson  // the docs are a little sketchy about this, do we need to NULL // terminate?
71e1342013-02-17Bill Welliver  if(subtype == .BINARY_OLD)
dd08cc2013-05-19Martin Nilsson  return sprintf("%-4H", data);
71e1342013-02-17Bill Welliver  else return data; } }