Source

fantomongo / fan / bson / Bson.fan

////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2010 Liam Staskawicz
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////


**
**  Bson
**
class Bson 
{  
  // data types
  static const Int MINKEY        := -1
  static const Int EOO           := 0
  static const Int DOUBLE        := 1
  static const Int STRING        := 2
  static const Int OBJECT        := 3
  static const Int ARRAY         := 4
  static const Int BINARY        := 5
  static const Int UNDEFINED     := 6
  static const Int OID           := 7
  static const Int BOOLEAN       := 8
  static const Int DATE          := 9
  static const Int NULL          := 10
  static const Int REGEX         := 11
  static const Int REF           := 12
  static const Int CODE          := 13
  static const Int SYMBOL        := 14
  static const Int CODE_W_SCOPE  := 15
  static const Int NUMBER_INT    := 16
  static const Int TIMESTAMP     := 17
  static const Int NUMBER_LONG   := 18
  static const Int MAXKEY        := 127
  
  // bson binary types
  static const Int BIN_FUNCTION  := 0x01
  static const Int BIN_LENGTH    := 0x02
  static const Int BIN_UUID      := 0x03
  static const Int BIN_MD5       := 0x05
  static const Int BIN_USER      := 0x80
  
  
  **
  ** Write a Fantom object to an OutStream in BSON format.
  ** The OutStream must have its endian member set to Endian.little
  ** This isn't checked for performance sake, but the data will not 
  ** be written correctly if it's not.
  **
  static Void write(OutStream out, Str:Obj? obj)
  {
    BsonWriter.write(out, obj)
  }
  
  static Void writeCStr(OutStream out, Str s)
  {
    BsonWriter.writeCStr(out, s)
  }
  
  **
  ** Parse a Fantom object from an InStream of BSON formatted data.
  ** The InStream must have its endian member set to Endian.little
  ** This isn't checked for performance sake, but the data will not 
  ** be read correctly if it's not.
  **
  static Str:Obj? read(InStream in)
  {
    return BsonReader.read(in)
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.