Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protocol-buffers-schema

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protocol-buffers-schema - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

test/fixtures/version.json

2

package.json
{
"name": "protocol-buffers-schema",
"version": "2.0.1",
"version": "2.0.2",
"description": "No nonsense protocol buffers schema parser written in Javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -209,2 +209,28 @@ var tokenize = require('./tokenize')

var onsyntaxversion = function (tokens) {
tokens.shift()
if (tokens[0] !== '=') throw new Error('Expected = but found ' + tokens[0])
tokens.shift()
var version = tokens.shift()
switch (version) {
case '"proto2"':
version = 2
break
case '"proto3"':
version = 3
break
default:
throw new Error('Expected protobuf syntax version but found ' + version)
}
if (tokens[0] !== ';') throw new Error('Expected ; but found ' + tokens[0])
tokens.shift()
return version
}
var onenumvalue = function (tokens) {

@@ -307,2 +333,3 @@ if (tokens.length < 4) throw new Error('Invalid enum value: ' + tokens.slice(0, 3).join(' '))

var schema = {
syntax: 3,
package: null,

@@ -316,2 +343,4 @@ imports: [],

var firstline = true
while (tokens.length) {

@@ -323,2 +352,7 @@ switch (tokens[0]) {

case 'syntax':
if (!firstline) throw new Error('Protobuf syntax version should be first thing in file')
schema.syntax = onsyntaxversion(tokens)
break
case 'message':

@@ -349,2 +383,3 @@ schema.messages.push(onmessage(tokens))

}
firstline = false
}

@@ -351,0 +386,0 @@

@@ -16,2 +16,4 @@ # protocol-buffers-schema

```proto
syntax = "proto2";
message Point {

@@ -47,2 +49,3 @@ required int32 x = 1;

{
syntax: 2,
package: null,

@@ -49,0 +52,0 @@ enums: [],

@@ -84,2 +84,5 @@ var onfield = function (f, result) {

var result = []
result.push('syntax = "proto' + schema.syntax + '";', '')
if (schema.package) result.push('package ' + schema.package + ';', '')

@@ -86,0 +89,0 @@

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": "tutorial",

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": [],

{
"syntax": 3,
"package": null,

@@ -3,0 +4,0 @@ "imports": ["./result.proto"],

@@ -16,3 +16,4 @@ var tape = require('tape')

tape('basic parse + stringify', function (t) {
t.same(schema.stringify(schema.parse(fixture('basic.proto'))), fixture('basic.proto'))
var syntax = 'syntax = "proto3";\n\n'
t.same(schema.stringify(schema.parse(fixture('basic.proto'))), syntax + fixture('basic.proto'))
t.end()

@@ -27,3 +28,4 @@ })

tape('complex parse + stringify', function (t) {
t.same(schema.stringify(schema.parse(fixture('complex.proto'))), fixture('complex.proto'))
var syntax = 'syntax = "proto3";\n\n'
t.same(schema.stringify(schema.parse(fixture('complex.proto'))), syntax + fixture('complex.proto'))
t.end()

@@ -81,1 +83,15 @@ })

})
tape('schema with syntax version', function (t) {
t.same(schema.parse(fixture('version.proto')), require('./fixtures/version.json'))
t.end()
})
tape('throws on misplaced syntax version', function (t) {
t.plan(1)
try {
schema.parse('message Foo { required int32 a = 1; }\n syntax = "proto3"')
} catch (err) {
t.ok(true, 'should fail')
}
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc